<template>
	<view class="k-i-box">
		<view class="bg">
			<view class="title">持卡人信息</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>持卡人姓名</view>
				<view class="i-b">
					<input type="text" v-model="cartInfo.member_name" placeholder="请输入内容" placeholder-class="i-p" />
				</view>
			</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>持卡人身份证号</view>
				<view class="i-b">
					<input type="text" v-model="cartInfo.id_card" placeholder="请输入内容" placeholder-class="i-p" />
				</view>
			</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>身份证有效期结束时间</view>
				<view class="i-b i-b4">
					<input type="number" v-model="cartInfo.id_card_begin" placeholder="请输入 开始时间"
						placeholder-class="i-p" />
					<text style="margin-right: 10rpx;">至</text>
					<input type="number" v-model="cartInfo.id_card_end" placeholder="请输入 结束时间"
						placeholder-class="i-p" />
				</view>
				<view class="i-b i-b5">
					<uni-icons type="info"></uni-icons>
					<view style="margin-left: 10rpx;">
						<view>
							<text>1.仅支持数字输入，例：2021年10月1日填</text>
							<text style="color: #9A1FE8;margin-left: 10rpx;">20211001</text>
						</view>
						<view>
							<text>2.如果身份证长期有效，则结束时间填</text>
							<text style="color: #9A1FE8;margin-left: 10rpx;">29991231</text>
						</view>
					</view>
				
				</view>
			</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>银行预留手机号</view>
				<view class="i-b">
					<input type="number" v-model="cartInfo.member_phone" placeholder="请输入内容" placeholder-class="i-p" />
				</view>
			</view>
		</view>

		<!-- 银行卡信息 -->
		<view class="bg">
			<view class="title">银行卡信息</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>银行卡号</view>
				<view class="i-b">
					<input type="text" v-model="cartInfo.bank_card" placeholder="请输入内容" placeholder-class="i-p" />
				</view>
			</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>开户银行</view>
				<view class="i-b">
					<input type="text" v-model="cartInfo.bank_name" placeholder="请输入内容" placeholder-class="i-p" />
				</view>
			</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>支行名称</view>
				<view class="i-b">
					<input type="text" v-model="cartInfo.sub_bank" placeholder="请输入内容" placeholder-class="i-p" />
				</view>
			</view>
			<view class="l-i">
				<view class="t"><text style="color: red;font-size: 34rpx;">*</text>银行卡类型</view>
				<view class="i-b i-b2">
					<text class="ka" :class="{active:cartInfo.card_type==1}"
						@click="cartInfo.card_type=1">借记卡/储蓄卡</text>
					<text class="ka" :class="{active:cartInfo.card_type==2}"
						@click="cartInfo.card_type=2">信用卡/贷记卡</text>
				</view>
			</view>
			<block v-if="cartInfo.card_type==2">
				<view class="l-i">
					<view class="t"><text style="color: red;font-size: 34rpx;">*</text>贷卡有效期</view>
					<view class="i-b">
						<input type="text" v-model="cartInfo.c_valid_date" placeholder="请输入内容"
							placeholder-class="i-p" />
					</view>
					<view class="i-b i-b2 i-b3">
						<uni-icons type="info"></uni-icons>
						<view class="msg">
							输入格式为<text style="color: #9A1FE8;margin-left: 10rpx;"> 月份 + 年份后两位</text>
							参考：2025 年 3 月 请输入 “0325”
						</view>
					</view>
				</view>
				<view class="l-i">
					<view class="t"><text style="color: red;font-size: 34rpx;">*</text>贷卡背面签名条末三位</view>
					<view class="i-b">
						<input type="text" v-model="cartInfo.c_vv_2" placeholder="请输入 贷卡背面签名条末三位"
							placeholder-class="i-p" />
					</view>
				</view>
			</block>
		</view>
		<!-- 遮挡层 -->
		<view class="block" v-if="options.type == 2"></view>
		<view class="btns">
			<view class="btn" @click="hardSumbit">{{options.type==1?'确认绑定':options.type==2?'删除银行卡':''}}</view>
		</view>
		<p2-pop ref="p2pop" @config="hardConfig" />
		<code-pop ref="codePop" @config="hardCode" />
		<p-pop ref="pPop" @config="hardpPop" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				options: {}, //页面参数
				cartInfo: {
					id: '',
					"bank_card": "",
					"bank_name": "",
					"sub_bank": "",
					"member_name": "",
					"id_card": "",
					"member_phone": "",
					"card_type": "1",
					"c_valid_date": "",
					"c_vv_2": "",
					"id_card_begin": "",
					"id_card_end": "",
					dataTime: []
				},
			}
		},
		onLoad(options) {
			this.options = options
			this.init()
		},
		methods: {
			init() {
				let title = '银行卡'
				if (this.options.type == 1) {
					title = '添加银行卡'
				}
				uni.setNavigationBarTitle({
					title
				})
				if (this.options.type == 2) {
					this.getCart()
				}
			},
			// 获取银行卡信息
			async getCart() {
				const res = await this.$axios('BankCard/det', 'POST', 'pt', {
					...this.options
				})
				if (res.data.code == 200) {
					this.cartInfo = res.data.data.info
				}
			},
			// 提交
			hardSumbit() {
				if (this.options.type == 1) {
					const cartInfo = {
						...this.cartInfo
					}
					if (!cartInfo.bank_card || !cartInfo.bank_name || !cartInfo.sub_bank || !cartInfo.member_name || !
						cartInfo.id_card || !cartInfo.member_phone || !cartInfo.card_type || cartInfo.card_type == 2 && !
						cartInfo.c_valid_date || cartInfo.card_type == 2 && !cartInfo.c_vv_2 || !cartInfo.id_card_begin ||
						!cartInfo.id_card_end) {
						return this.$api.msg('请完善提交信息！')
					}
					this.$refs.p2pop.open({
						title: '银行卡绑定功能验证提醒',
						content: '为了保障您的财产安全，银行卡绑定功能设置了手机号验证环节。这是我们对您账户安全的一项额外保护措施，确保只有持卡人可以进行银行卡绑定操作。',
						config: '开始验证'
					})
				}
				if (this.options.type == 2) {
					this.$refs.pPop.open({
						title: '操作确认',
						content: '检测到您正在删除已绑定银行卡信息，删除后绑定信息将全部失效无法恢复，请谨慎操作；若当前银行卡为最后一张，删除操作将自动失效。',
						config: '确认删除'
					})
				}
			},
			// 绑卡提交
			async hardConfig(e) {
				if (!e) {
					return
				}
				uni.showLoading({
					title: '发送中'
				})
				const res = await this.$axios('BankCard/add', 'POST', 'pt', {
					...this.cartInfo
				})
				uni.hideLoading()
				if (res.data.code == 200) {
					this.cartInfo.id = res.data.data.id
					this.$refs.codePop.open({
						title: '银行卡绑定功能验证提醒'
					})
				} else {
					uni.showModal({
						title: '温馨提示',
						content: res.data.data
					})
				}
			},
			// 提交验证码
			async hardCode(e) {
				if (!e.type) {
					return
				}
				if (!this.cartInfo.id) {
					return this.$api.msg('提交失败请重试')
				}
				uni.showLoading({
					title: '提交中'
				})
				const res = await this.$axios('BankCard/ver', 'POST', 'pt', {
					...this.cartInfo,
					sms_code: e.code
				})
				uni.hideLoading()
				let content = '提交成功'
				if (res.data.code != 200) {
					content = res.data.data
				}
				uni.showModal({
					title: '温馨提示',
					content,
					success() {
						if (res.data.code == 200) {
							this.$navBack()
						}
					}
				})
			},
			// 删除确认提交
			async hardpPop(e) {
				if (!e) {
					return
				}
				uni.showLoading({
					title: '删除中'
				})
				const res = await this.$axios('BankCard/del', 'POST', 'pt', {
					...this.options
				})
				uni.hideLoading()
				let content = '删除成功'
				if (res.data.code != 200) {
					content = res.data.data
				}
				uni.showModal({
					title: '温馨提示',
					content,
					success() {
						if (res.data.code == 200) {
							this.$navBack()
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.k-i-box {
		min-height: 100vh;
		background-color: #fdf8ff;
		font-family: Source Han Sans;
		font-variation-settings: "opsz" auto;
		padding: 30rpx 0 174rpx;

		.bg {
			width: 694rpx;
			border-radius: 16rpx;
			background: #FFFFFF;
			margin: 0 auto 30rpx;
			padding: 20rpx 28rpx;

			.title {
				font-size: 28rpx;
				font-weight: bold;
				color: #13001E;
				position: relative;
				padding-left: 20rpx;

				&:before {
					content: '';
					width: 8rpx;
					height: 20rpx;
					background: #9A1FE8;
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
					border-radius: 10rpx;
					box-shadow: 0px 0px 2rpx 2rpx rgba(81, 0, 132, 0.1);
				}
			}

			.l-i {
				padding-top: 20rpx;

				.t {
					display: flex;
					align-items: center;
					color: #13001E;
					font-size: 24rpx;
				}

				.i-b {
					width: 638rpx;
					box-sizing: border-box;
					border-bottom: 2rpx solid rgba(204, 202, 205, 0.5);
					padding: 20rpx 0;

					input {
						padding: 0 10rpx;
						font-size: 28rpx;
					}

					.i-p {
						color: #999999;
					}
				}

				.i-b1 {
					border: none;
					padding: 20rpx 0 0;
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #5B5B5B
				}

				.i-b2 {
					display: flex;
					justify-content: space-between;
					border: none;

					.ka {
						width: 306rpx;
						height: 60rpx;
						line-height: 60rpx;
						border-radius: 378rpx;
						text-align: center;
						background: rgba(#999999, 0.1);
						color: #999999;
					}

					.active {
						background: #9A1FE8;
						color: #FFFFFF;
					}
				}

				.i-b3 {
					.msg {
						color: #5B5B5B;
						font-size: 24rpx;
						padding-left: 10rpx;
						display: flex;
						align-items: center;
						flex-wrap: wrap;
					}
				}

				.i-b4 {
					display: flex;
					align-items: center;
				}
				.i-b5 {
					display: flex;
					font-size: 24rpx;
				}
			}
		}

		.btns {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			background: #FFFFFF;
			box-shadow: 0px 8px 20px 0px rgba(0, 0, 0, 0.3);
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 30rpx 0 60rpx;
			z-index: 10;

			.btn {
				color: #FFFFFF;
				font-size: 32rpx;
				font-weight: bold;
				width: 690rpx;
				height: 84rpx;
				line-height: 84rpx;
				text-align: center;
				border-radius: 24rpx;
				background: linear-gradient(94deg, #FF38E5 0%, #8813E2 61%);
			}
		}

		.block {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 100vh;
			opacity: 1;
			z-index: 8;
		}
	}
</style>